package com.maimao.goods.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.maimao.model.goods.SpecDetails;
import com.maimao.model.kill.KillGoods;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @author MaoLin Wang
 * @date 2021/4/13 4:59 下午
 */
@Configuration
public class CaffeineCacheConfig {

    public static final int INITIAL_CAPACITY = 200;
    public static final int MAXIMUM_SIZE = 500;

    @Bean("specCache")
    public Cache<Integer, SpecDetails> specCache() {
        return Caffeine.newBuilder()
                // 设置最后一次写入或访问后经过固定时间过期
                .expireAfterWrite(1, TimeUnit.DAYS)
                // 初始的缓存空间大小
                .initialCapacity(INITIAL_CAPACITY)
                .maximumSize(MAXIMUM_SIZE)
                .build();
    }

}
